<template>
  <div class="row no-gutters">
    <div class="col-12 padding-20">
      <el-input placeholder="手机号/账号" v-model.trim="username"></el-input>
    </div>

    <div class="col-12">
      <el-input
        show-password
        placeholder="密码"
        v-model.trim="password"
      ></el-input>
    </div>

    <div class="col-12 padding-20">
      <el-input
        show-password
        placeholder="确认密码"
        v-model.trim="sure"
      ></el-input>
    </div>

    <div class="col-12">
      <el-button
        @click="register()"
        style="width: 100%; background-color: #41b883"
        ><span style="color: white; font-size: 15px">立即注册</span></el-button
      >
    </div>
  </div>
</template>

<script>
import { fake } from "../../assets/fake";
export default {
  data() {
    return {
      username: "",
      password: "",
      sure: "",
    };
  },
  methods: {
    register() {
      let _this = this;
      let isSuccess = true;
      fake.account.forEach((value) => {
        if (value.username === _this.username) {
          isSuccess = false;
        }
      });
      if (isSuccess) {
        if (this.username.length <= 11 && this.username.length > 0) {
          if (_this.password.length <= 18 && _this.password.length >= 6) {
            if (_this.password === _this.sure) {
              fake.account.push({
                username: _this.username,
                password: _this.password,
                user: {
                  info: {
                    id: fake.account.length + 1 + "",
                    nick: _this.username,
                    avatar: require(`logo`),
                    sex: "男",
                    desc: "该用户什么也没留下",
                    creatTime: fake.methods.getDateFormat(),
                  },
                  line: [
                    {
                      content: "关注",
                      list: [],
                    },
                    {
                      content: "粉丝",
                      list: [],
                    },
                    {
                      content: "收藏",
                      list: [],
                    },
                    {
                      content: "谁看过我",
                      list: [],
                    },
                  ],
                  set: {
                    showFocus: true,
                    showFans: true,
                    showLikes: true,
                    showViews: true,
                    showArticle: true,
                  },
                  isAdmin: false,
                  articleList: [],
                  msgBox:[],
                },
              });
              _this.$emit("success");
              _this.$message({
                message: "注册成功,快去登录吧",
                type: "success",
              });
              console.log(fake.account);
            } else {
              _this.$message.error("两次密码不一致");
            }
          } else {
            _this.$message.error("密码长度应在6-18位之间");
          }
        } else {
          _this.$message.error("账号名不得超过11位且低于0位");
        }
      } else {
        _this.$message.error("账号已存在");
      }
    },
  },
};
</script>

<style>
</style>